#coding=utf-8

import re
import urllib2
import os

search = 'computer'
url = "http://www.baidu.com/s?wd=" + search

file = 'urls_data.txt'

def get_url(f):
	web = urllib2.urlopen(url)
	html = web.read()

	links = re.findall('"((http|ftp)s?://.*?)"',html)
	for i in links:
		print i[0]
		if (len(i[0]) < 256):
			f.write(i[0] + '\n')

f = open(file,'w+')
get_url(f)

f.seek(0)
lines = len(f.readlines())
print 'there are %d lines' %(lines)
f.close()

